otvet=0
n=int(input())
x1=n%10
x2=n//10%10
x3=n//100%10
x4=n//1000
x5=x1*10+x2
x6=x2*10+x3
x7=x3*10+x4
x8=x1*100+x2*10+x3
x9=x2*100+x3*10+x4
for i in range(2, int(x1**0.5)+1):
    if x1%i==0:
        break
else:
    otvet=max(otvet,x1)
for i in range(2, int(x2**0.5)+1):
    if x2%i==0:
        break
else:
    otvet=max(otvet,x3)
for i in range(2, int(x3**0.5)+1):
    if x3%i==0:
        break
else:
    otvet=max(otvet,x4)
for i in range(2, int(x4**0.5)+1):
    if x4%i==0:
        break
else:
    otvet=max(otvet,x5)
for i in range(2, int(x4**0.5)+1):
    if x5%i==0:
        break
else:
    otvet=max(otvet,x6)
for i in range(2, int(x5**0.5)+1):
    if x6%i==0:
        break
else:
    otvet=max(otvet,x7)
for i in range(2, int(x6**0.5)+1):
    if x7%i==0:
        break
else:
    otvet=max(otvet,x8)
for i in range(2, int(x8**0.5)+1):
    if x8%i==0:
        break
else:
    otvet=max(otvet,x9)
for i in range(2, int(x9**0.5)+1):
    if x9%i==0:
        break
else:
    otvet=max(otvet,n)
for i in range(2, int(n**0.5)+1):
    if n%i==0:
        break
else:
    otvet=max(otvet,n)
print(otvet)
